package com.ruoyi.dictionaries.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dictionaries.domain.PoliticalStatus;
import com.ruoyi.dictionaries.service.IPoliticalStatusService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 政治面貌Controller
 *
 * @author gdslovehy
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/dictionaries/politicalstatus")
public class PoliticalStatusController extends BaseController
{
    @Autowired
    private IPoliticalStatusService politicalStatusService;

    /**
     * 查询政治面貌列表
     */
    //@PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:list')")
    @GetMapping("/list")
    public TableDataInfo list(PoliticalStatus politicalStatus)
    {
        startPage();
        List<PoliticalStatus> list = politicalStatusService.selectPoliticalStatusList(politicalStatus);
        return getDataTable(list);
    }

    /**
     * 导出政治面貌列表
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:export')")
    @Log(title = "政治面貌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PoliticalStatus politicalStatus)
    {
        List<PoliticalStatus> list = politicalStatusService.selectPoliticalStatusList(politicalStatus);
        ExcelUtil<PoliticalStatus> util = new ExcelUtil<PoliticalStatus>(PoliticalStatus.class);
        util.exportExcel(response, list, "政治面貌数据");
    }

    /**
     * 获取政治面貌详细信息
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(politicalStatusService.selectPoliticalStatusById(id));
    }

    /**
     * 新增政治面貌
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:add')")
    @Log(title = "政治面貌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PoliticalStatus politicalStatus)
    {
        politicalStatus.setId(IdUtils.fastSimpleUUID());
        return toAjax(politicalStatusService.insertPoliticalStatus(politicalStatus));
    }

    /**
     * 修改政治面貌
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:edit')")
    @Log(title = "政治面貌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PoliticalStatus politicalStatus)
    {
        return toAjax(politicalStatusService.updatePoliticalStatus(politicalStatus));
    }

    /**
     * 删除政治面貌
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:politicalstatus:remove')")
    @Log(title = "政治面貌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(politicalStatusService.deletePoliticalStatusByIds(ids));
    }
}
